package com.example.redissentinel;

import io.lettuce.core.ReadFrom;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.LettuceClientConfigurationBuilderCustomizer;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,
        MongoAutoConfiguration.class,
        MongoDataAutoConfiguration.class
})

public class RedisSentinelApplication {

    public static void main(String[] args) {
        SpringApplication.run(RedisSentinelApplication.class, args);
    }


    /**
     * @description: TODO 配置主从读写分离
     * @author louby0923
     * @date 2024-03-09 12:46
     * @version 1.0
     */
    @Bean
    public LettuceClientConfigurationBuilderCustomizer configurationBuilder() {

        //REPLICA_PREFERRED:优先从slave(replica)节点读取，所有的slave都不可用才读取master
        return confingBuilder -> confingBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);

    }


}
